<?php
/**
 * User: robinfai
 * Date: 15/1/20
 * Time: 20:17
 * @var $this HomeController
 */
$cs = Yii::app()->clientScript;
$cs->registerScriptFile($this->module->assetsUrl . '/jquery-1.10.2.min.js');
$cs->registerScriptFile($this->module->assetsUrl . '/bootstrap.min.js');
$cs->registerScriptFile($this->module->assetsUrl . '/jquery.nouislider.min.js');
$cs->registerScriptFile($this->module->assetsUrl . '/bootstrap-material-design/dist/js/material.js');
$cs->registerScriptFile($this->module->assetsUrl . '/bootstrap-daterangepicker/moment.js');
$cs->registerScriptFile($this->module->assetsUrl . '/bootstrap-daterangepicker/daterangepicker.js');
$cs->registerCssFile($this->module->assetsUrl . '/bootstrap-daterangepicker/daterangepicker-bs3.css');


?><!DOCTYPE html>
<html>
<!-- MEMO: update me with `git checkout gh-pages && git merge master && git push origin gh-pages` -->
<head>
    <meta charset="utf-8">
    <title>Profiler性能分析工具</title>
    <link href="<?php echo $this->module->assetsUrl ?>/css/bootstrap.css" rel="stylesheet">
    <link href="<?php echo $this->module->assetsUrl ?>/bootstrap-material-design/dist/css/material.css"
          rel="stylesheet">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style>
        .modal.in .modal-dialog {
            z-index: 1045;
        }
    </style>
</head>
<body>
<div class="navbar navbar-default">
    <div class="container">

        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse"
                    data-target=".navbar-responsive-collapse">
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="javascript:void(0)">Profiler</a>
        </div>
        <div class="navbar-collapse collapse navbar-responsive-collapse">
            <ul class="nav navbar-nav">
                <li class="active"><a href="javascript:void(0)">首页</a></li>
            </ul>
        </div>
    </div>
</div>
<div class="container">
    <div class="well shadow-z-3">

        <?php $form = $this->beginWidget('CActiveForm', array(
            'id'          => 'profiling-log-list-form',
            'method'      => 'get',
            'htmlOptions' => array(
                'class'        => 'form-horizontal',
                'autocomplete' => 'off',
                'enctype'      => 'multipart/form-data',
            ),
        ));
        /* @var CActiveForm $form */
        ?>
        <fieldset>
            <legend>查询</legend>
            <div class="form-group">
                <label for="dateRange" class="col-lg-2 control-label">日期范围</label>

                <div class="col-lg-4">
                    <input type="text" class="form-control date-range" id="dateRange">
                    <input type="hidden" class="form-control" name="ProfilingLog[logTime][start]"
                           value="<?php echo isset($log->logTime['start']) ? $log->logTime['start'] : '' ?>">
                    <input type="hidden" class="form-control" name="ProfilingLog[logTime][end]"
                           value="<?php echo isset($log->logTime['end']) ? $log->logTime['end'] : '' ?>">
                </div>
                <label for="profilingTime" class="col-lg-2 control-label">耗时</label>

                <div class="col-lg-4">
                    <?php echo $form->textField($log, 'profilingTime', array('class' => 'form-control')) ?>
                </div>
            </div>
            <div class="form-group">
                <label for="action" class="col-lg-2 control-label">controller</label>

                <div class="col-lg-4">
                    <?php echo $form->dropDownList($log, 'controller', CMap::mergeArray(array_combine($log->getControllerList(), $log->getControllerList()), array('' => '请选择')), array('class' => 'form-control')) ?>
                </div>
                <label for="action" class="col-lg-2 control-label">action</label>

                <div class="col-lg-4">
                    <?php echo $form->dropDownList($log, 'action', CMap::mergeArray(array_combine($log->getActionList(), $log->getActionList()), array('' => '请选择')), array('class' => 'form-control')) ?>
                </div>
            </div>
            <div class="form-group">
                <div class="col-lg-10 col-lg-offset-2">
                    <button type="reset" class="btn btn-default">重置</button>
                    <button type="submit" class="btn btn-primary">查询</button>
                </div>
            </div>
        </fieldset>
        <?php $this->endWidget(); ?>
    </div>
    <div class="well shadow-z-3">
        <div class="alert alert-info">
            <div class="row">
                <div class="col-md-2">最小耗时</div>
                <div class="col-md-2"><?php echo round($log->minProfilingTime, 2) ?>ms</div>
                <div class="col-md-2">平均耗时</div>
                <div class="col-md-2"><?php echo round($log->avgProfilingTime, 2) ?>ms</div>
                <div class="col-md-2">最大耗时</div>
                <div class="col-md-2"><?php echo round($log->maxProfilingTime, 2) ?>ms</div>
            </div>
        </div>
        <?php
        $log->logTime = '';
        $this->widget('zii.widgets.grid.CGridView', array(
            'id'            => 'profiling-log-grid',
            'dataProvider'  => $log->search(),
            'itemsCssClass' => 'table',
            'pagerCssClass' => 'text-right',
            'cssFile'       => false,
            'pager'         => array(
                'cssFile'              => false,
                'header'               => '',
                'internalPageCssClass' => false,
                'selectedPageCssClass' => 'active',
                'htmlOptions'          => array('class' => 'pagination',)
            ),
            'columns'       => array(
                'id',
                'controller',
                'action',
                array(
                    'name'  => 'profilingTime',
                    'value' => function ($data) {
                            return round($data->profilingTime, 2) . ' ms';
                        }
                ),
                array(
                    'name'   => 'logTime',
                    'filter' => false,
                ),
            ),
        )); ?>
    </div>
</div>
<div class="modal" id="detail">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title">性能日志</h4>
            </div>
            <div class="modal-body">

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(function () {


        if ($('[name="ProfilingLog[logTime][start]"]').val() &&
            $('[name="ProfilingLog[logTime][end]"]').val()) {
            $('.date-range').val($('[name="ProfilingLog[logTime][start]"]').val() + " - " +
                $('[name="ProfilingLog[logTime][end]"]').val())
        }
        $('.date-range').daterangepicker({
            format: "YYYY-MM-DD"
        }, function (start, end, label) {

            $('[name="ProfilingLog[logTime][start]"]').val(start.format('YYYY-MM-DD'));
            $('[name="ProfilingLog[logTime][end]"]').val(end.format('YYYY-MM-DD'));

        });

        $('#profiling-log-grid tbody tr').click(function () {

            var data = $(this).find('td:first').text();
            var url = '<?php echo $this->createUrl('detail')?>';
            if(url.indexOf('?')>-1){
                url += "&id="+data;
            }else{
                url += "?id="+data;
            }
            window.open(url);
        })
    })
</script>
</body>
</html>